package com.azkj.album.view.widgets.staggedrv;

import android.content.Context;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;


public abstract class StaggedAdapter<FakeModel> extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    public List<FakeModel> datas = new ArrayList<>();
    private Context c;

    public StaggedAdapter(Context c) {
        this.c = c;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {

        return addViewHolder(viewGroup,i);

    }

    @Override
    public void onBindViewHolder( RecyclerView.ViewHolder viewHolder, int i) {

        bindView(viewHolder, i);

    }

    @Override
    public int getItemCount() {
         return datas.size();
    }

    /**
     * 下拉刷新
     *
     * @param datas
     */
    public void refresh(List<FakeModel> datas) {

        this.datas = datas;

        notifyItemRangeChanged(0, datas.size());


    }

    /**
     * 加载更多
     *
     * @param datas
     */
    public void loadMore(List<FakeModel> datas) {

        int startPos = this.datas.size() - 1;

        notifyItemRangeInserted(startPos, datas.size());

        this.datas.addAll(datas);

    }

    public abstract RecyclerView.ViewHolder addViewHolder(ViewGroup viewGroup, int i);

    public abstract void bindView(RecyclerView.ViewHolder viewHolder, int i);

}
